const deepseek = require('./LLM/deepseek');
const prompts = require('./LLM/prompts');

class HttpRequest2Docs {
    /**
     * 生成API文档
     * @param {object} requestDesc HTTP请求描述
     * @param {string} format 文档格式(markdown/html)
     * @returns {Promise<string>} 生成的文档内容
     */
    async generateDocumentation(requestDesc, format = 'markdown') {
        const validFormats = ['markdown', 'html'];
        if (!validFormats.includes(format)) {
            throw new Error(`不支持的格式: ${format}`);
        }

        try {
            const response = await deepseek.call(
                prompts.HttpRequest2Docs(requestDesc, format),
                { temperature: 0.2 }
            );

            return response
                .trim()
                .replace(/^```(markdown|html)?/, '')
                .replace(/```$/, '');
        } catch (error) {
            console.error('生成文档失败:', error);
            throw new Error('生成文档失败: ' + error.message);
        }
    }
}

module.exports = new HttpRequest2Docs();
